// pages/index/tiwen/tiwen.js

const app=getApp()

import request from "../../../utils/request"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    message:'a',
  },

  onClickLeft(){
    wx.navigateBack()
  },
// 发表
  async fabiao(){
    let message=this.data.message
    let userId=1
    let time=this.formatTime(new Date())
    console.log(message)
    console.log(userId)
    console.log(time)    

    console.log(app.globalData.user)
    console.log(app.globalData.user.id)
    userId=app.globalData.user.id

    const res = await request.post('/dmy/psychologicalQuesion/add',{
      "userId": userId,
      "questionContent": message,
      "questionTime": time
    })
    // res.then((res)=>{
    //   alert("成功")
    // }).catch((err)=>{
    //   alert("失败")
    // })

    wx.navigateBack()
  },
  // 格式化时间为 YYYY-MM-DD HH:mm:ss
  formatTime(date) {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份补零
    const day = String(date.getDate()).padStart(2, '0');         // 日期补零
    const hours = String(date.getHours()).padStart(2, '0');      // 小时补零
    const minutes = String(date.getMinutes()).padStart(2, '0');  // 分钟补零
    const seconds = String(date.getSeconds()).padStart(2, '0');  // 秒数补零

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      this.setData({
        message:""
      })
  },

})